<?php
class Video extends CI_Controller
{
	private $data;
	function video()
	{
		parent::__construct();
		$this->layout->setLayout('admin');
		$auth = $this->session->userdata('auth');
		if(!$auth)
		{
			redirect('/auth/login');
		}
	}
	function index()
	{
		$this->load->library('pagination');
		//paging
		$config['base_url'] =base_url()."index.php/product/index";
		$config['total_rows'] = $this->db->count_all('video');
		$config['per_page'] = '10';
		$config['uri_segment'] = 3;
		$this->pagination->initialize($config);
		//-------------
		$offset=$this->uri->segment(3);
		$data['video']=$this->video_model->getAllProduct($offset,$config['per_page']);
		$this->layout->view('listvideo',$data);
	}
	function delete()
	{
		$id=$this->input->post('hidID');
		$arrId=$this->input->post('chkid');
		if($id)
			$this->video_model->delete($id);
		elseif($arrId)
		{
			foreach ($arrId as $id)
				$this->video_model->delete($id);
		}
		redirect('video');
	}
	function add()
	{
		$data['value']=array(
								'id'=>null,
								'name'=>'',
								'link'=>''
							);
		$data['action']='insert';
		$this->layout->view('addvideo',$data);
	}
	function insert()
	{
		$video=$this->input->post();
		//var_dump($video);die;
		$data=array(	'name'=>$video['txtname'],
						'link'=>$video['txtlink']
						);
						
		$this->video_model->addproduct($data);
		redirect('video');
	}
	function update()
	{
		$id=$this->uri->segment(3);
		$video=$this->video_model->getProduct($id);
		$Objvideo=$video[0];
		//var_dump($video);die;
		$data['value']=array(	'id'	=>$Objvideo->id,
								'name'	=>$Objvideo->name,
								'link'	=>$Objvideo->link
								);
		$data['action']='submitupdate';
		$this->layout->view('addvideo',$data);
	}
	function submitupdate()
	{
		$video=$this->input->post();
		$data=array(	'id'=>$video['hidID'],
						'name'=>$video['txtname'],
						'link'=>$video['txtlink']
					);
		$this->video_model->update($data);
		redirect('video');
	}
}